#include <stdio.h>
#include <stdlib.h>
/*
Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
Explanation: merged array = [1,2,3] and median is 2.

Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.50000
Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
*/

int compare(const void *a, const void *b){
    return (*(int *)a) - (*(int *)b);
}

double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){
    int merged[nums1Size + nums2Size];
    int idx = 0;
    for (int i = 0; i < nums1Size; i++) {
        merged[idx] = nums1[i];
        idx ++;
    }
    for (int i = 0; i < nums2Size; i++) {
        merged[idx] = nums2[i];
        idx ++;
    }
    qsort(merged, nums1Size + nums2Size, sizeof(int), compare);
    if ((nums1Size + nums2Size) % 2 == 0) {
        return (double)(merged[(nums1Size + nums2Size) / 2 - 1] + merged[(nums1Size + nums2Size) / 2]) / 2;
    } else {
        return merged[(nums1Size + nums2Size) / 2];
    }
}

int main() {
    int nums1[2] = {1,2};
    int nums2[1] = {3};
    printf("%f\n", findMedianSortedArrays(nums1, 2, nums2, 1));
}